// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1

package role

import (
	"audio-server/internal/model"
	"context"
	"database/sql"
	"time"

	"audio-server/internal/svc"
	"audio-server/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoleSaveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleSaveLogic {
	return &RoleSaveLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleSaveLogic) RoleSave(req *types.RoleSaveReq) (resp bool, err error) {

	roleModel := model.NewSysRoleModel(l.svcCtx.Conn)

	_, err = roleModel.Insert(l.ctx, &model.SysRole{
		CreateTime:  time.Now(),
		Description: sql.NullString{String: req.Description, Valid: true},
		IsAdmin:     int64(req.IsAdmin),
		Name:        req.Name,
	})
	if err != nil {
		return false, err
	}
	return true, nil
}
